package com.yxuan.springboot.controller;

import com.yxuan.springboot.model.TestBlock;
import com.yxuan.springboot.service.TestBlockService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * 
 * @author zchao
 *   TestBlock控制器
 * @date 2023-05-16 14:22:57
 */
@Controller
@Api(tags = "")
@RequestMapping(value = "/testblock", method = {RequestMethod.POST,RequestMethod.GET})
public class TestBlockController extends BaseController<TestBlock>{

//    增删改查区块
    @Autowired
    private TestBlockService testBlockService;

//    新增区块
    @Override
    @RequestMapping(value = "/addblock",method = RequestMethod.POST)
    public String saveT(@RequestBody TestBlock entity) throws IOException {
        Date date = new Date();
        Timestamp timestamp = new Timestamp(date.getTime());
        entity.setCreateTime(timestamp);
        entity.setUpdateTime(timestamp);
        return super.saveT(entity);
    }


//    删除区块
    @Override
    @RequestMapping(value = "/delblock",method = RequestMethod.POST)
    public String delete(@RequestBody TestBlock testBlock) {
        return super.delete(testBlock);
    }

//    修改区块

    @Override
    @RequestMapping(value = "/updateblock",method = RequestMethod.POST)
    public String updT(@RequestBody TestBlock entity) throws Exception {
        Date date = new Date();
        Timestamp timestamp = new Timestamp(date.getTime());
        entity.setCreateTime(timestamp);
        entity.setUpdateTime(timestamp);
        return super.updT(entity);
    }

//    查询所有区块
    @Override
    @RequestMapping(value = "/allblock",method = RequestMethod.GET)
    public List<TestBlock> loadAll() {
        return super.loadAll();
    }
}
